home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH10 / SRC / ARCTAN2.BAS next >
BASIC Source File  |  1996-03-22  |  619b  |  28 lines

  1. Attribute VB_Name = "AtcTan"
  2. Option Explicit
  3.  
  4. ' ************************************************
  5. ' Return the arc tangent of y/x taking into
  6. ' account the proper quadrant.
  7. ' ************************************************
  8. Function Arctan2(x As Single, y As Single)
  9. Const PI = 3.14159
  10. Const PI_OVER_2 = PI / 2
  11.  
  12. Dim theta As Single
  13.  
  14.     If x = 0 Then
  15.         If y > 0 Then
  16.             Arctan2 = PI_OVER_2
  17.         Else
  18.             Arctan2 = -PI_OVER_2
  19.         End If
  20.     Else
  21.         theta = Atn(y / x)
  22.         If x < 0 Then theta = PI + theta
  23.         Arctan2 = theta
  24.     End If
  25. End Function
  26.  
  27.  
  28.